﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace YTSK.Frm
{

    public class FrmVouchDKPBase : Report.ReportData
    {
        public string _retailcode;
        private ToolStrip _toolstrip;
        #region 初始化

        public FrmVouchDKPBase(Control main, DataGridView dg, string ReportCode, ToolStrip toolstrip) :
            base(main, dg, ReportCode)
        { _toolstrip = toolstrip; }
        #endregion

        public override void InitControl()
        {
            base.InitControl();
            foreach (ToolStripItem bar in _toolstrip.Items)
            {
                if (bar.Text.Length > 0)
                { bar.Click += toolbar_click; }
            }
        }

        #region 双击选中行
        public void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                var row = _dg.CurrentRow;
                if (row == null) { return; }
                var obj = row.Cells["retail_code"].Value.ObjToString();
                if (obj.Length>0)
                {
                    _retailcode = obj;
                }
                var parent = (Form)_main.Parent;
                parent.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion


        #region 工具栏事件
        public virtual void toolbar_click(object sender, EventArgs e)
        {
            if (sender.GetType() != typeof(ToolStripButton)) { return; }
            var bt = (ToolStripButton)sender;
            var text = bt.Text;
            switch (text)
            {
                case "导出":
                    Common.handleDataGrid.ExportExcel(base._dg);
                    break;
                case "发票开具":
                    dataGridView1_MouseDoubleClick(null, null);
                    break;
                case "退出":
                    var parent = (Form)_main.Parent;
                    parent.Close();
                    break;
                default:
                    MessageBox.Show("没有找到程序");
                    break;
            }

        }
        #endregion
    }

}
